package de.tudarmstadt.gdi1.project.analyse;

import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;

import de.tudarmstadt.gdi1.project.alphabet.Alphabet;
import de.tudarmstadt.gdi1.project.alphabet.Dictionary;

public class DictionaryTool implements Dictionary {

	public DictionaryTool(Alphabet alphabet, String text) {
		this.alphabet = alphabet;
		Scanner s = new Scanner(text);
		while (s.hasNext()) {
			String[] w = s.next().split("[,||.||?||!]");
			if (alphabet.allows(w[0])) {
				dict.add(w[0]);
			}
		}
		dict.remove("");
		s.close();
	}

	Alphabet alphabet;
	TreeSet<String> dict = new TreeSet<String>();

	@Override
	public Iterator<String> iterator() {
		return dict.iterator();
	}

	@Override
	public boolean contains(String word) {
		return dict.contains(word);
	}

	@Override
	public Alphabet getAlphabet() {
		return alphabet;
	}

	@Override
	public int size() {
		return dict.size();
	}

	@Override
	public String get(int index) {
		String word = dict.first();
		for (int i = 0; i < index; i++) {
				word = dict.higher(word);
			}
		return word;
	}

}
